import { getInsuranceRechargeDetail, getRechargeDetailInfo, getContractDetailInfo } from '../../api/insurance.js'
import user from '../../../utils/user'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        status: '',
        insureCompanyType:'',
        projectType:'',
        id:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad (options) {
        console.log(this.options,  'optionsoptions')
        this.setData({
            projectType:options.type,
            id:options.id
        })
        if(options.type === 'payRenew'){
            this.getRechargeDetailInfo()
        }else if(options.type == 'contract'){
            console.log('调用啦')
            this.getContractDetailInfo()
        }else{
            getInsuranceRechargeDetail({
                id: options.id
            }).then(res=>{
                console.log(res)
                this.setData({
                    status: res.status,
                    photo: res.voucherUrl,
                    money: res.rechargeAmount,
                    insureCompanyType:user.insureCompanyType
                })
            })
        }
        
    },
    preview(){
        wx.previewImage({
            urls: [this.data.photo],
        })
    },
    async getRechargeDetailInfo () {
        const result = await getRechargeDetailInfo({
            id:this.data.id
        })
        console.log('调用啦')
        this.setData({
            status: result.status,
            photo: result.voucherUrl,
            money: result.payMoney,
            insureCompanyType:user.insureCompanyType
        })
    },
    // 电子签充值记录
    async getContractDetailInfo(){
        const result = await getContractDetailInfo({
            id:this.data.id
        })
        console.log(result,'resultresult')
        this.setData({
            status: result.status,
            photo: result.voucherUrl,
            money: result.rechargeAmount,
            insureCompanyType:user.insureCompanyType
        })
    }
})